home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / DEMO_APP / HEADER_L.JAV < prev    next >
Encoding:
Text File  |  1996-10-04  |  4.5 KB  |  144 lines

  1. package sub_arctic.demo_apps;
  2.  
  3. import sub_arctic.lib.listbox;
  4. import sub_arctic.lib.manager;
  5. import sub_arctic.lib.interactor;
  6. import sub_arctic.input.event;
  7. import sub_arctic.input.callback_object;
  8.  
  9. import java.util.Vector;
  10.  
  11. /**
  12.  * This is a subclass of listbox which we use to display our mail
  13.  * headers in.
  14.  */
  15. public class header_listbox extends listbox implements callback_object {
  16.   /**
  17.    * We need a handle to the applet.
  18.    */
  19.   mail_test applet;
  20.   /**
  21.    * This is the function that gets called when we double click 
  22.    * on a mail message.
  23.    */ 
  24.   public void handle_double_click() {
  25.     create_message();
  26.   }
  27.   /**
  28.    * Propagate the constructor ... we know that our listboxes are
  29.    * going to use cosntraints for their sizes, so we just put 10,10
  30.    * as the size and know it will get overrided later.
  31.    * We pass the applet because we need to be able to see some
  32.    * of its data structures for creating new messages.
  33.    */
  34.   public header_listbox(boolean single, mail_test a) {
  35.     super(10,10,single,null);
  36.     /* set the callback object to be this ... can't do this in the
  37.        super() call as we can't reference this yet */
  38.     set_callback_obj(this);
  39.     /* set the draggability to true */
  40.     set_allow_dragging(true);
  41.     applet=a;
  42.   }
  43.   /**
  44.    * This function sizes a new message for you.
  45.    */
  46.   public static void size_message(message_display display) {
  47.     display.set_w(530);
  48.     display.set_h(300);
  49.     /* now if the text is actually smaller than this size, we should
  50.      * use that size */
  51.     if (display.text_height()<display.h()) {
  52.       display.set_h(display.text_height()+12);
  53.     }
  54.     if (display.text_width()<display.w()) {
  55.       display.set_w(display.text_width()+12);
  56.     }
  57.   }
  58.   /**
  59.    * This pops up a message when they double click on it.
  60.    */
  61.   public void create_message() {
  62.     message msg=(message)focused();
  63.     message_display display=new message_display(msg,applet);
  64.     
  65.     /* we know that the parent() of this object is the top_object
  66.      * and the parent() of that is the applet 
  67.      */
  68.     applet.playing_field().add_child(display);
  69.     display.set_x(10);
  70.     display.set_y(10);
  71.     size_message(display);
  72.   }
  73.   /**
  74.    * This is the function that gets called when the user initiates a
  75.    * drag. We want to create a message icon which we can drag.
  76.    */
  77.   public void handle_drag(event evt) {
  78.     message_icon mi;
  79.     message msg[];
  80.     Vector v;
  81.     int i;
  82.     /* make sure images are loaded... not really needed 
  83.      now but might be shortly */
  84.     if (message_display.delete_icon==null) {
  85.       message_display.load_icons(applet);
  86.     }
  87.     /* now build the icon and then set it to be the drag focus */
  88.     /* remove the listbox from the focus of the simple drag*/
  89.     manager.simple_drag_focus.remove_from_focus(this,evt);
  90.     /* figure out how many objects are currently selected */
  91.     v=selected_set();
  92.     /* build an array of messages that is that size */
  93.     msg=new message[v.size()];
  94.     /* initialize the array of messages*/
  95.     for (i=0; i<msg.length;++i) {
  96.       msg[i]=(message)v.elementAt(i);
  97.     }
  98.     /* create a new icon */
  99.     mi=new message_icon(msg,evt.global_x(),evt.global_y(),
  100.             get_top_level(),applet,true /* from here */);
  101.     /* make it the move-drag focus */
  102.     manager.move_drag_focus.set_focus_to(mi,evt,null);
  103.   }
  104.   /**
  105.    * This is what gets called in response to a callback.
  106.    */
  107.   public void callback(interactor from_obj, 
  108.                event      evt,
  109.                int        callback_num, 
  110.                Object     callback_info) {
  111.  
  112.     /* are we getting called back by our own object? */
  113.     if (from_obj==this) {
  114.       if (callback_num==listbox.DOUBLE_CLICK) {
  115.     handle_double_click();
  116.       }
  117.       if (callback_num==listbox.DRAG) {
  118.     handle_drag(evt);
  119.       }
  120.       return;
  121.     }
  122.     /* this is used so that the scrollbar callback works properly */
  123.     super.callback(from_obj, evt, callback_num, callback_info);
  124.   }
  125.  
  126. }
  127.   
  128. /*=========================== COPYRIGHT NOTICE ===========================
  129.  
  130. This file is part of the subArctic user interface toolkit.
  131.  
  132. Copyright (c) 1996 Scott Hudson and Ian Smith
  133. All rights reserved.
  134.  
  135. The subArctic system is freely available for most uses under the terms
  136. and conditions described in 
  137.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  138. and appearing in full in the lib/interactor.java source file.
  139.  
  140. The current release and additional information about this software can be 
  141. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  142.  
  143. ========================================================================*/
  144.